package com.wkh.datastructure;

import java.util.Arrays;
//插入排序
public class InsertionSort {
    public static void main(String[] args) {
        int[] arr = {5,454,23242,4,23,5,32,42,3,412};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void sort(int[]arr){
        insertion(arr,1);
    }
    private static void insertion(int[] arr,int low){
        if (low == arr.length){
            return;
        }
        int tem = arr[low];
        int i = low - 1;
        while (i >= 0 && tem < arr[i]){
             arr[i+1] = arr[i];
            i--;
        }
        if (i+1 != low){
            arr[i+1] = tem;
        }
        insertion(arr,low+1);
    }
}
